var occupied_header = new Array();
var occupied_menu = new Array();

for(i=1;i<=7;i++) {
 occupied_header[i] = 0;
 occupied_menu[i] = 0; 
}

function CreateLayer(text, id, t, l) {
if(document.layers)
 {
  var str="<LAYER ID=smenu" + id + " TOP=" + t
         + " LEFT=" + l + " class=\"dropdownmenu\" onmouseover=\"occupied_menu["
         + id + "]=1;\" onmouseout=\"Turn('"
         + id + "',0);occupied_menu[" + id
         + "]=0;\" VISIBILITY=hide>"
         + text + "</LAYER>";
  document.write(str);
 }
 else
 {
  var strng="<div id=\"smenu" + id + "\" class=\"dropdownmenu\" style=\"position:absolute;top:"
           + t + ";left:" + l
           + ";visibility:hidden;z-index: 2345\""
           + " onmouseover=\"occupied_menu[" + id
           + "]=1;\" onmouseout=\"Turn('" + id
           + "',0);occupied_menu[" + id
           + "]=0;\">" + text + "</div>";
  document.write(strng);
 }
 }
 
function Turn(id, mode) {
  if(mode)
  {
   eval("setTimeout(\"On(" + id + ", " + mode + ");\",100)");
   }
  else {
   eval("setTimeout(\"Off(" + id + ", " + mode + ");\",100)");
   }
}

 function On(id, mode){
  if(occupied_header[id])   
    if(document.layers)
		eval("document.layers['smenu" + id + "']").visibility = "show";
	else
	{ 
   		pos = 	findPos(id);
   		var _tmp_smenu = document.getElementById("smenu" + id);
   		if (_tmp_smenu!= null)
   		{
   			_tmp_smenu.style.left = pos[0]+"px";
   			_tmp_smenu.style.top = (pos[1]+15)+"px";
   			_tmp_smenu.style.visibility = 'visible';
   		}
    	/*
    	eval("smenu" + id).style.left = pos[0];
		eval("smenu" + id).style.top = pos[1]+15;
		eval("smenu" + id).style.visibility = 'visible';
		*/
		//	alert(eval("smenu" + id).style.top);
	}
 }
 
 function Off(id, mode){
  if(!occupied_menu[id] && !occupied_header[id])
   if(document.layers)
    eval("document.layers['smenu" + id + "']").visibility = "hide";
	else
	{
		var _tmp_smenu = document.getElementById("smenu" + id);
   		if (_tmp_smenu != null)
   		{
   			_tmp_smenu.style.visibility = 'hidden';
   		}
   		//eval("smenu" + id).style.visibility = 'hidden';
	}	
 }
 
 function findPos(id)
 {
 if(document.layers){   //Netscape 4
    x = document.layers.layerMenu.pageX
    y = document.layers.layerMenu.pageY
  }else{ //other browsers
    x=0; y=0; var el,temp;
//    el = bw.ie4?document.all["divMenu"]:document.getElementById("divMenu");
    el = document.getElementById("ddmitem"+id);
    if(el.offsetParent){
      temp = el
      while(temp.offsetParent){ //Looping parent elements to get the offset of them as well
        temp=temp.offsetParent; 
        x+=temp.offsetLeft
        y+=temp.offsetTop;
      }
    }

    x+=el.offsetLeft
    y+=el.offsetTop;
  }
  //Returning the x and y as an array
  return [x,y]
}